package com.traceability.service.impl;

import com.traceability.dao.NodeMapper;
import com.traceability.entity.Node;
import com.traceability.service.NodeService;
import com.traceability.utils.UUIDUtil;
import com.traceability.vo.NodeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Objects;

@Service
public class NodeServiceImpl implements NodeService {
    @Autowired
    private NodeMapper nodeMapper;

    @Override
    @Transactional
    public String eventCreate(String tenantId, NodeVO nodeVO) {
        Node node = new Node();
//        node.setId(Long.toString(SnowFlake.nextId()));
        node.setId(UUIDUtil.creatUUID());
        node.setTenantId(tenantId);
        node.setEventId(nodeVO.getEventId());
        node.setEventType(nodeVO.getEventType());
        node.setNumber(nodeVO.getNumber());
        nodeMapper.eventCreate(node);
        return node.getId();
    }

    @Override
    @Transactional
    public String eventUpdate(String tenantId, NodeVO nodeVO) {
        Node node = nodeMapper.findNodeBytenantIdAndId(tenantId, nodeVO.getId());
        if (Objects.nonNull(node)) {
//            System.out.println("存在数据");
            node.setEventId(nodeVO.getEventId());
            node.setEventType(nodeVO.getEventType());
            node.setNumber(nodeVO.getNumber());
            nodeMapper.nodeUpdate(node);
        }
        return "successful";

    }
}
